package com.uci.scheduleshare.adapters;

import java.util.List;

import com.uci.scheduleshare.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
 * CS 190 Spring 2012
 * RecentActivityAdapter.java
 * The Adapter for displaying recent activity
 * 
 * @author Patrick Hsu, Lauren Ko, Pomi Park
 *
 */
public class RecentActivityAdapter extends BaseAdapter {
	
	private List<String> activities;
	private Context context;
	
	public RecentActivityAdapter(Context context, List<String> activities) {
		this.context = context;
		this.activities = activities;
	}
	
	@Override
	public int getCount() {
		return activities.size();
	}

	@Override
	public Object getItem(int position) {
		return activities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ActivityTextHolder holder; // A holder for containing the activity text
		if(convertView == null) { // If the view is null, inflate a new view
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.activities_row, parent, false);
			holder = new ActivityTextHolder();
			holder.text = (TextView) convertView.findViewById(R.id.activities_content);
			convertView.setTag(holder);

		} else {
			holder = (ActivityTextHolder)convertView.getTag();
		}
		String content = activities.get(position);
		holder.text.setText(content);
		return convertView;
	}
	
	static class ActivityTextHolder{
		TextView text;
	}

}
